package com.yuyou.train.user.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yuyou.train.service.api.user.entity.UserHwPraise;
import com.yuyou.train.user.mapper.UserHwPraiseMapper;
import com.yuyou.train.user.service.IUserHwPraiseService;
import com.yuyou.train.util.bean.ResBoolSimpleInfo;
import com.yuyou.train.util.enums.user.UserHwEnums;
import com.yuyou.train.util.tool.Sequence;
import com.yuyou.train.util.tool.UUIDUtil;

@Service
public class UserHwPraiseServiceImpl implements IUserHwPraiseService{

	@Autowired
	private UserHwPraiseMapper userHwPraiseMapper;
	
	@Override
	public int deleteByPrimaryKey(String id) {
		return userHwPraiseMapper.deleteByPrimaryKey(id);
	}

	@Override
	public int insert(UserHwPraise record) {
		record.setId(Sequence.getSequence().getNextId());
		record.setCreateTime(new Date());
		return userHwPraiseMapper.insert(record);
	}

	@Override
	public UserHwPraise selectByPrimaryKey(String id) {
		return userHwPraiseMapper.selectByPrimaryKey(id);
	}

	@Override
	public int updateByPrimaryKeySelective(UserHwPraise record) {
		record.setUpdateTime(new Date());
		return userHwPraiseMapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public List<UserHwPraise> findUserHwPraise(UserHwPraise record) {
		return userHwPraiseMapper.findUserHwPraise(record);
	}

	@Override
	public ResBoolSimpleInfo<String> addHwPraise(UserHwPraise record) {
		this.insert(record);
		return ResBoolSimpleInfo.getSuccessInfo();
	}

	@Override
	public ResBoolSimpleInfo<String> addHwPraiseList(List<String> list,
			String hwId,String hwType, String type) {
		this.deleteByHwIdAndType(hwId, hwType,type);
		for(String b:list){
			UserHwPraise hwPrise=new UserHwPraise();
			hwPrise.setContent(b);
			hwPrise.setHwType(hwType);
			hwPrise.setType(type);
			hwPrise.setUserHwId(hwId);
			this.addHwPraise(hwPrise);
		}		
		return ResBoolSimpleInfo.getSuccessInfo();
	}

	@Override
	public ResBoolSimpleInfo<String> deleteByHwIdAndType(String userHwId, String hwType,String type) {
		userHwPraiseMapper.deleteByHwIdAndType(userHwId, hwType,type);
		return ResBoolSimpleInfo.getSuccessInfo();
	}

	@Override
	public List<String> findUserHwPraiseStr(String userHwId,String hwType,String type) {
		return userHwPraiseMapper.findUserHwPraiseStr(userHwId, hwType, type);
	}


}